import {
	mapMutations
} from 'vuex';
import * as index from '@/api/index.js'
export default {
	data() {
		return {
			userinfo:{},
			list:[],
			choice:'',
			emptyShow: false,
			text:''
		}
	},
	onPageScroll(e) {
		
	},
	computed: {
	
	},
	watch: {
	
	},
	onShow() {
		this.userinfo = uni.getStorageSync('userinfo')
		this.getaddress()
	},
	onLoad(option) {
		this.choice = option.choice
	},
	// 上拉触底
	onReachBottom() {

	},
	// 下拉刷新
	onPullDownRefresh() {

	},
	onNavigationBarButtonTap(e) {
	   this.$tools.navigate('/pagesA/user/addAddress/index')
	},
	methods: {
		...mapMutations(['converList']),
		addBnt() {
			this.$tools.navigate('/pages/user/addAddress/index')
		},
		// 获取地址列表
		getaddress() {
			index.deliveryAddressList({userId:this.userinfo.userId}).then(res=>{
				this.list = res.list
				if(this.list.length == 0) {
					this.emptyShow = true
				} else {
					this.emptyShow = false
				}
			})
		},
		detailsBnt(item) {
			if(this.choice) {
				uni.setStorageSync('address', item)
				uni.navigateBack(-1)
			} else {
				this.$tools.navigate('/pages/user/addAddress/index?id=' + item.id)
			}
		},
		editBnt(item) {
			this.$tools.navigate('/pages/user/addAddress/index?id=' + item.id)
		},
		logoTime(e){
			this.ids = e
			console.log(e,'地址详情')
			this.text = '确定删除地址吗?'
			setTimeout(res=>{
				this.$refs.entrePopup.open()
			},300)
		},
		// 删除本条记录
		showBntentre() {
			index.deliveryAddressDel({id:this.ids}).then(res=>{
				this.getaddress()
			})
		},
		// 返回
		returnBnt() {
			uni.navigateBack(-1)
		},
	}
}
